<?php
namespace app\admin\controller;

use think\Controller;
use app\admin\model\Bbs as BbsModel;
use think\facade\Request;
 

class Bbs extends Controller
{

  

 


 
    public function index() 
    {
            $this->assign('title', '留言板'); 
 

            $list = BbsModel::show();
            // 把分页数据赋值给模板变量list 
            $this->assign('list', $list);


            // 渲染模板输出
            return $this->fetch('index');


 
    }
    public  function status($id,$status){

        $status = BbsModel::status($id,$status);

        $this->success('更新成功！' );

    }
 
 
    public function view(){

        $id = input('id'); 


        $view = BlogModel::view($id);
         
        $this->assign('view', $view);
 


        // 渲染模板输出
        return $this->fetch();
    }
    public  function del($id){

        if (Request::isPost()) {

            $del = BbsModel::del($id);
    
            $this->success('删除成功！' );
         }

         echo "no";


    }
    public  function edit($id,$title,$content){

        if (Request::isPost()) {

        $status = BbsModel::edit($id,$title,$content);

        $this->success('编辑成功！' );

        }

    }

    public function add(){

      

     if (Request::isPost()) {
 
        $title   = input('title'); 
        $content = input('content'); 

        if ($title=='') {
           
            //错误页面的默认跳转页面是返回前一页，通常不需要设置
            $this->error('标题不能为空');
        }

        $list = BbsModel::add($title,$content);


                          
        return     $this->success('留言发布成功');
     


     }

        // 渲染模板输出
        return $this->fetch();

    }
}
